<?php

namespace App\Repositories;

use App\Models\TestingResultAttribute;
use Cache;
class TestingResultAttributeRepository extends Repository
{
    static $tag = 'testing.result.attr';


    /**
     * @param $id
     * @return mixed
     */
    public function getById($id)
    {
       $cacheKey = getCacheKey('testing.cache_key.result_attribute.info');
        $cacheKey = $cacheKey.$id;
        $value = $this->remember($cacheKey, function () use ($id) {
            return TestingResultAttribute::where('id', $id)
                ->select('id as attr_id','title','note')
                ->first()->toarray();
        });
        return $value;

    }

    public function getAttrOptions(){
        $cacheKey = getCacheKey('testing.cache_key.result_attribute.options');
        $value = $this -> remember($cacheKey,function(){
            $list = TestingResultAttribute::all();
            $data = [];
            if($list){
                $obj = array();
                foreach ($list as $key => $val){
                    $obj['id'] = $val['id'];
                    $obj['text'] = $val['tag'];
                    array_push($data,$obj);
                }
            }
            return $data;
        });
        return $value;
    }



    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }


    public function model()
    {
        return app(TestingResultAttribute::class);
    }

    public function tag()
    {
        return self::$tag;
    }
}